package com.luke.springcloud.healthcheck;

import com.netflix.appinfo.HealthCheckHandler;
import com.netflix.appinfo.InstanceInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

/**
 * @Descrtption 自定义监控检查
 * @Author luke
 * @Date 2020/4/21
 **/
@Slf4j
@Component
public class MyHealthCheckHandler implements HealthCheckHandler {

    @Autowired
    private MyHealthIndicator myHealthIndicator;

    @Override
    public InstanceInfo.InstanceStatus getStatus(InstanceInfo.InstanceStatus instanceStatus) {
        Status status = myHealthIndicator.health().getStatus();
        //log.info("status: {}",status);
        if(Status.UP.equals(status)){
            //log.info("InstanceInfo.InstanceStatus.UP");
            return InstanceInfo.InstanceStatus.UP;
        }else{
            //log.info("InstanceInfo.InstanceStatus.DOWN");
            return InstanceInfo.InstanceStatus.DOWN;
        }
    }

}
